package com.zhicheng.mapper;


import com.zhicheng.pojo.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    /**
     * 动态条件查询
     * @param shoppingCart
     * @return
     */
    List<ShoppingCart> list(ShoppingCart shoppingCart);

    @Select("select * from shopping_cart where user_id = #{userId} and selected = 1")
    List<ShoppingCart> orderList(ShoppingCart shoppingCart);

    /**
     * 添加购物车
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart(name, `desc`, img_url, user_id, good_id, price, create_time) " +
            "values (#{name},#{desc},#{imgUrl},#{userId},#{goodId},#{price},#{createTime})")
    void insert(ShoppingCart shoppingCart);

    /**
     * 根据购物车id删除
     * @param id
     */
    @Delete("delete from shopping_cart where id =#{id}")
    void deleteById(Long id);

    /**
     * 根据用户id删除
     */
    @Delete("delete from shopping_cart where user_id =#{userId} and selected = 1 ")
    void deleteByUserId(Long userId);

    @Update("update shopping_cart set selected = #{selected} where good_id = #{goodId} and user_id = #{userId}")
    void updateCart(ShoppingCart cart);
}
